#!/usr/bin/env bash
if [[ ! -e server.conf ]];then
  echo "server.conf not found"
  exit 1
fi
# 判断 ./html目录是否存在
if [[ ! -e html ]];then
  echo "html directory not found"
  exit 1
fi
# 判断 Dockerfile是否存在
if [[ ! -e Dockerfile ]];then
  echo "Dockerfile not found"
  exit 1
fi
docker build -t ccr.ccs.tencentyun.com/liumou/thrive-nginx:latest .
if [[ $? -ne 0 ]];then
  echo "build failed"
  exit 1
fi

if [[ -e server.conf ]];then
  docker run -d --name nginx -P -v $(pwd)/server.conf:/etc/nginx/conf.d/server.conf -v $(pwd)/html:/usr/share/nginx/html ccr.ccs.tencentyun.com/liumou/thrive-nginx:latest
  if [[ $? -ne 0 ]];then
    echo "run failed"
    exit 1
  fi
  echo "runsuccess"
fi